package com.interview.javabase.tcpupd;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

/**
 * @author: zsg
 * @description:
 * @date: 2019/6/8 21:07
 * @modified:
 */
public class SocketClient {
    public static void main(String[] args) {
        try {
            Socket socket = new Socket("127.0.0.1", 60000);
            OutputStream outputStream = socket.getOutputStream();
            outputStream.write("哈哈".getBytes());

            InputStream inputStream = socket.getInputStream();
            byte[] bytes = new byte[1024];
            int read = inputStream.read(bytes);
            System.out.println(read);

            System.out.println("字符串长度为 = "+ new String(bytes,0,read));
            outputStream.close();
            inputStream.close();
            socket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
